package cn.manyufun.myf.ui.user.model;

import org.json.JSONException;
import org.json.JSONObject;

import cn.manyufun.myf.api.Api;
import cn.manyufun.myf.api.HostType;
import cn.manyufun.myf.bean.UserDetail;
import cn.manyufun.myf.common.base.BaseModel;
import cn.manyufun.myf.common.baserx.RxSchedulers;
import cn.manyufun.myf.common.commonutils.APIUtils;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import rx.Observable;

/**
 * @author Kevin Xiao
 * @date Create Date: 2018-01-16
 * @Description
 */
public class UserInfoModel implements BaseModel {
    public Observable<UserDetail> loadUserInfo() {
        JSONObject root = new JSONObject();
        JSONObject head = APIUtils.getHeadParamter();
        try {
            root.put("Head", head);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), root.toString());
        return Api.getDefault(HostType.manyufun).getUserDetail(requestBody)
                .compose(RxSchedulers.<UserDetail>io_main());
    }
}
